// pages/distributionOrders/distributionOrders.js
var app = getApp();
var api = require("../../api.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navindex: 0,
    orderstate: [
      { txt: '全部' },
      { txt: '进行中' },
      { txt: '已完成' }
    ],
    is_pay: 0,
    orderList: [],
    page: 1,
    pageSize: 10,
    hasMoreData: true,
    total: 0,
    According: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  // 切换状态
  click: function (e) {
    wx.showLoading();
    var id = e.currentTarget.dataset.id;
    console.log(id)
    this.setData({
      navindex: id,
      is_pay: id,
      page: 1,
      orderList: []
    })
    this.getList();
  },
  // 获取列表
  getList() {
    var that = this;
    app.request({
      url: api.distribution.order_list,
      method: 'post',
      data: {
        is_pay: that.data.is_pay,
        page: that.data.page
      },
      success: function (res) {
        var orderLists = that.data.orderList;
        if (res.code == 1) {
          wx.hideLoading();
          if (that.data.page == 1) {
            orderLists = []
          }
          var orderList = res.data.data;
          if (orderList.length == 0) {
            that.setData({
              orderList: that.data.orderList,
              hasMoreData: false,
              According: true
            })
          } else if (orderList.length < that.data.pageSize) {
            that.setData({
              orderList: orderLists.concat(orderList),
              hasMoreData: false,
              According: false
            })
          } else {
            that.setData({
              orderList: orderLists.concat(orderList),
              page: that.data.page + 1,
              hasMoreData: true,
              According: false
            })
          }
        } else {
          wx.showToast({
            title: '暂无数据',
            duration: 1000
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    wx.showLoading();
    this.getList()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.data.page = 1
    console.log(this.data.page)
    this.getList()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    console.log(this.data.hasMoreData);
    if (this.data.hasMoreData) {
      this.getList()
    } else {
      wx.showToast({
        title: '没有更多数据',
        duration: 1000,
        icon: 'none'
      })
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})